import {getUserFromJwt} from '~/utils/serveCommon'
import {getUserTagsByPage} from '~/server/database/repositories/tag'
export default defineEventHandler(async(context)=>{
  try{
    const {page,kind} = getQuery(context) || {}// 读取参数
    if(!page || !kind){
      return sendError(context,createError({
        statusCode: 400,
        statusMessage: '参数错误!',
      }))
    }else{
      if(!['expenses','income'].includes(kind+'') || isNaN(parseInt(page+''))){
        return sendError(context,createError({
          statusCode: 400,
          statusMessage: '参数类型错误!',
        }))
      }
    }
    const user_id = getUserFromJwt(context)
    const realPage = + page
    return await getUserTagsByPage(user_id, realPage, kind as TagType)
  }
  catch(error){
    return sendError(context, createError({
      statusCode: 400,
      statusMessage: '获取数据失败!',
    }))
  }
})